package com.itheima.反射.Constructor.demo3;

import java.lang.reflect.Constructor;

public class Demo {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException {
        Class<?> aClass = Class.forName("com.itheima.反射.Constructor.demo3.Student");
        //1. 获取Student类中所有公共的构造方法对象并遍历打印
        Constructor<?>[] constructors = aClass.getConstructors();
        for (Constructor<?> constructor : constructors) {
            System.out.println(constructor);
        }
        System.out.println("-----------------");
        //2. 获取Student类中所有构造方法对象并遍历打印
        Constructor<?>[] declaredConstructors = aClass.getDeclaredConstructors();
        for (Constructor<?> declaredConstructor : declaredConstructors) {
            System.out.println(declaredConstructor);
        }
        System.out.println("-----------------");
        //3. 获取Student类中公共的无参构造方法对象并打印
        Constructor<?> constructor = aClass.getConstructor();
        System.out.println(constructor);
        System.out.println("-----------------");
        //4. 获取Student类中公共的带参构造方法(String,int)对象并打印
        Constructor<?> constructor1 = aClass.getConstructor(String.class, int.class);
        System.out.println(constructor1);
        System.out.println("-----------------");
        //5. 获取Student类中私有的带参构造方法(String)对象并打印
        Constructor<?> declaredConstructor = aClass.getDeclaredConstructor(String.class);
        System.out.println(declaredConstructor);

    }
}
